﻿using Emgu.CV;
using Emgu.CV.Util;
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading.Tasks;

namespace ContourSplit
{
	public class CGHelper
	{
		[DllImport(@"CGHelper.dll", CallingConvention = CallingConvention.Cdecl)]
		private static extern void getInscribedRectangleProxy(int[] x, int[] y, int count, ref Rectangle result);

		public static Rectangle getInscribedRectangle(VectorOfPoint hull)
		{
			Rectangle r = new Rectangle();
			var x = hull.ToArray().Select(e => e.X).ToArray();
			var y = hull.ToArray().Select(e => e.Y).ToArray();
			getInscribedRectangleProxy(x, y, x.Length, ref r);
			return r;
		}
	}
}
